package com.arithmeticEveryDay.blueBridge;

import java.util.Scanner;

/*

4 5
1 2
2 4
3 4
4 5

                        1选                      1不选
                    /        \
                  2选        2不选
                 /  \
               3选  3不选


 */

public class Main19681 {
    
    
    private static int dfs(int n, int m, int[] weight, int[] value, int maxValue, int curValue, int curWeight, int i) {
        if (i == n) {
            if (curValue > maxValue) {
                maxValue = curValue;
            }
            return maxValue;
        }
        int temp = maxValue;
        // 选第i个
        if (curWeight + weight[i] <= m) {
            temp = dfs(n, m, weight, value, maxValue, curValue + value[i], curWeight + weight[i], i+1);
        } else {
            temp = curValue;
        }
        // 不选第i个
        maxValue = dfs(n, m, weight, value, maxValue, curValue, curWeight, i+1);
        return temp > maxValue ? temp : maxValue;
    }
    
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[] weight = new int[n];
        int[] value = new int[n];
        for (int i = 0; i < n; i++) {
            weight[i] = scan.nextInt();
            value[i] = scan.nextInt();
        }
        System.out.println(dfs(n, m, weight, value, 0, 0, 0, 0));

    }

    

}
